﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Drawing.Imaging;
using Excel = Microsoft.Office.Interop.Excel;



namespace CRM1
{
    public partial class Form1 : Form
    {
        string mDataFolder = "..\\Data\\";

        string CityLocationDetailsFileName = "MapData.xml";

        string mExcelFilename = "MDData.xlsm";

        Image mImage = null;
        
        public List<CWCExcelData> mExcelDataList = new List<CWCExcelData>();
        
        MapData mMapData = new MapData();

        Font mTitleFont = new Font("Comic Sans", 15, FontStyle.Bold);
        Font mReadingFont = new Font("Ariel", 12, FontStyle.Regular);

        public Form1()
        {
            mImage = Image.FromFile(mDataFolder + "MapSrc.jpg");
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //LoadAndProcessData();
            LoadXML();
            PopulateDataGrid();
        }

        void LoadAndProcessData()
        {
            this.WindowState = FormWindowState.Maximized;
            Graphics gObj = null;
            this.pictureBox1.Image = mImage.Clone() as Image;
            this.pictureBox1.Size = this.pictureBox1.Image.Size;
            gObj = Graphics.FromImage(this.pictureBox1.Image);
            this.Text = "Loading...";

            mExcelDataList.Clear();
            mMapData = new MapData();

            LoadXML();

            PopulateDataGrid();

            LoadExcel();

            PlotRainfall(gObj);

            pictureBox1.Invalidate();

            PlotMinTempData(gObj);

            pictureBox1.Invalidate();

            Plot24HrsDep(gObj);

            pictureBox1.Invalidate();

            PlotTempDiff(gObj);

            pictureBox1.Invalidate();

            PlotTempDpDep(gObj);

            pictureBox1.Invalidate();

            PlotP24(gObj);

            pictureBox1.Invalidate();

            PlotCorrectedPressure(gObj);

            pictureBox1.Invalidate();

            PlotPressureDepFromNormal(gObj);

            pictureBox1.Invalidate();

            this.Text = "Loading Complete!";
        }

        # region data population
        void PopulateDataGrid()
        {
            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                this.dataGridView1.Rows.Add(md.StationName,md.StationCode, md.StationID, md.X, md.Y);
            }
            this.dataGridView1.Enabled = false;
        }

        void PlotRainfall(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[0].OffsetX + mMapData.mMapDetails[0].TitleOffsetX;

            int titleY = mMapData.mMapDetails[0].OffsetY + mMapData.mMapDetails[0].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[0].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[0].FontSize, FontStyle.Regular);

            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        Brush rfbrush = new System.Drawing.SolidBrush(ed.mRFColor);
                        Brush wxbrush = new System.Drawing.SolidBrush(ed.mWXColor);
                        int x = md.X + mMapData.mMapDetails[0].OffsetX + mMapData.mMapDetails[0].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[0].OffsetY + mMapData.mMapDetails[0].ReadingOffsetY;

                        if (ed.Rainfall != null)
                            inGobj.DrawString(ed.Rainfall, mReadingFont, rfbrush, x, y);
                        
                        if(ed.wx != null)
                            inGobj.DrawString(ed.wx, mReadingFont, wxbrush, x + 15, y);
                    }
                }
            }
        }

        void PlotPressureDepFromNormal(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[7].OffsetX + mMapData.mMapDetails[7].TitleOffsetX;

            int titleY = mMapData.mMapDetails[7].OffsetY + mMapData.mMapDetails[7].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[7].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[7].FontSize, FontStyle.Regular);

            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        brush = new System.Drawing.SolidBrush(ed.mPressDepFromNormalColor);
                        int x = md.X + mMapData.mMapDetails[7].OffsetX + mMapData.mMapDetails[7].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[7].OffsetY + mMapData.mMapDetails[7].ReadingOffsetY;
                        inGobj.DrawString(ed.PressDepFromNormal.ToString(), mReadingFont, brush, x, y);
                    }
                }
            }
        }

        void PlotCorrectedPressure(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[6].OffsetX + mMapData.mMapDetails[6].TitleOffsetX;

            int titleY = mMapData.mMapDetails[6].OffsetY + mMapData.mMapDetails[6].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[6].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[6].FontSize, FontStyle.Regular);

            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        brush = new System.Drawing.SolidBrush(ed.mCorrectedPressureColor);
                        int x = md.X + mMapData.mMapDetails[6].OffsetX + mMapData.mMapDetails[6].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[6].OffsetY + mMapData.mMapDetails[6].ReadingOffsetY;
                        inGobj.DrawString(ed.CorrectedPressure.ToString(), mReadingFont, brush, x, y);
                    }
                }
            }
        }


        void PlotP24(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[5].OffsetX + mMapData.mMapDetails[5].TitleOffsetX;

            int titleY = mMapData.mMapDetails[5].OffsetY + mMapData.mMapDetails[5].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[5].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[5].FontSize, FontStyle.Regular);

            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        brush = new System.Drawing.SolidBrush(ed.mP24Color);
                        int x = md.X + mMapData.mMapDetails[5].OffsetX + mMapData.mMapDetails[5].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[5].OffsetY + mMapData.mMapDetails[5].ReadingOffsetY;
                        inGobj.DrawString(ed.P24.ToString(), mReadingFont, brush, x, y);
                    }
                }
            }
        }

        void PlotTempDpDep(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[4].OffsetX + mMapData.mMapDetails[4].TitleOffsetX;

            int titleY = mMapData.mMapDetails[4].OffsetY + mMapData.mMapDetails[4].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[4].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[6].FontSize, FontStyle.Regular);


            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        brush = new System.Drawing.SolidBrush(ed.mM24HrsDpDepColor);
                        int x = md.X + mMapData.mMapDetails[4].OffsetX + mMapData.mMapDetails[4].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[4].OffsetY + mMapData.mMapDetails[4].ReadingOffsetY;
                        inGobj.DrawString(ed.M24HrsDpDep.ToString(), mReadingFont, brush, x, y);
                    }
                }
            }
        }
        void PlotTempDiff(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[3].OffsetX + mMapData.mMapDetails[3].TitleOffsetX;

            int titleY = mMapData.mMapDetails[3].OffsetY + mMapData.mMapDetails[3].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[3].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[3].FontSize, FontStyle.Regular);


            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        brush = new System.Drawing.SolidBrush(ed.mTempDiffColor);
                        int x = md.X + mMapData.mMapDetails[3].OffsetX + mMapData.mMapDetails[3].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[3].OffsetY + mMapData.mMapDetails[3].ReadingOffsetY;
                        inGobj.DrawString(ed.TempDiff.ToString(), mReadingFont, brush, x, y);
                    }
                }
            }

        }

        void Plot24HrsDep(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[2].OffsetX + mMapData.mMapDetails[2].TitleOffsetX;

            int titleY = mMapData.mMapDetails[2].OffsetY + mMapData.mMapDetails[2].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[2].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[2].FontSize, FontStyle.Regular);

            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        brush = new System.Drawing.SolidBrush(ed.mM24HrsDepColor);
                        int x = md.X + mMapData.mMapDetails[2].OffsetX + mMapData.mMapDetails[2].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[2].OffsetY + mMapData.mMapDetails[2].ReadingOffsetY;

                        inGobj.DrawString(ed.M24HrsDep.ToString(), mReadingFont, brush, x, y);
                    }
                }
            }

        }

        void PlotMinTempData(Graphics inGobj)
        {
            Brush brush = new System.Drawing.SolidBrush(Color.Black);

            int titleX = mMapData.mMapDetails[1].OffsetX + mMapData.mMapDetails[1].TitleOffsetX;

            int titleY = mMapData.mMapDetails[1].OffsetY + mMapData.mMapDetails[1].TitleOffsetY;

            inGobj.DrawString(mMapData.mMapDetails[1].Title, mTitleFont, brush, titleX, titleY);

            mReadingFont = new Font("Ariel", mMapData.mMapDetails[1].FontSize, FontStyle.Regular);

            foreach (CityLocationDetails md in mMapData.mCityLocationDetails)
            {
                foreach (CWCExcelData ed in mExcelDataList)
                {
                    if (md.StationID == ed.StationID)
                    {
                        brush = new System.Drawing.SolidBrush(ed.mMinTempColor);
                        int x = md.X + mMapData.mMapDetails[1].OffsetX + mMapData.mMapDetails[1].ReadingOffsetX;
                        int y = md.Y + mMapData.mMapDetails[1].OffsetY + mMapData.mMapDetails[1].ReadingOffsetY;
                        inGobj.DrawString(ed.MinTemp.ToString(), mReadingFont, brush, x, y);
                    }
                }
            }

        }
#endregion

        Dictionary<int, string> mStationCodeList = new Dictionary<int, string>();
        #region exceldata
        private void LoadExcel()
        {
            Excel._Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            Excel.Range range;

            string str;

            int rCnt = 0;
            int cCnt = 0;

            xlApp = new Excel.ApplicationClass();

            string path = Application.StartupPath.Substring(0,Application.StartupPath.LastIndexOf("\\"));

            string filename = path +"\\Data\\"+ mExcelFilename;

            xlWorkBook = xlApp.Workbooks.Open(filename, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(6);

            range = xlWorkSheet.UsedRange;

            this.Text = xlWorkSheet.Name;
            this.Text = "Loading...";

            for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
            {
                CWCExcelData excelRowData = new CWCExcelData();
                /*
                  int colorNumber = System.Convert.ToInt32(((Range) worksheet.Cells[rowNumber,columnNumber]).Interior.Color);
                    Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                 */
                for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
                {
                    if (cCnt == 1)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            str = (range.Cells[rCnt, cCnt] as Excel.Range).Value2.ToString();
                            if (str.Contains('['))
                            {
                                string stationName = str.Substring(0, str.IndexOf('['));
                                int si = str.IndexOf('[');
                                int ei = str.Length - si;
                                int stationid = Convert.ToInt32(str.Substring(str.IndexOf('[') + 1, 5));
                             
                                if (stationid != 0)
                                {
                                    if (!mStationCodeList.ContainsKey(stationid))
                                        mStationCodeList.Add(stationid, stationName);
                                   
                                    excelRowData.StationName = stationName;
                                    excelRowData.StationID = stationid;
                                }
                            }
                        }
                    }

                    if (cCnt == 2)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;

                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mRFColor = color;
                                string temp = Convert.ToString(o);
                                excelRowData.Rainfall = temp;
                            }
                        }
                    }

                    if (cCnt == 3)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                string temp = Convert.ToString(o);
                                excelRowData.wx = temp;
                                excelRowData.mWXColor = color;
                            }
                        }
                    }

                    if (cCnt == 4)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mMinTempColor = color;
                                int temp = Convert.ToInt32(o);
                                excelRowData.MinTemp = temp;
                            }
                        }
                    }
                    if (cCnt == 5)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mM24HrsDepColor = color;
                                int temp = Convert.ToInt32(o);
                                excelRowData.M24HrsDep = temp;
                            }
                        }
                    }
                    if (cCnt == 6)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mTempDiffColor = color;
                                int temp = Convert.ToInt32(o);
                                excelRowData.TempDiff = temp;
                            }
                        }
                    }

                    if (cCnt == 7)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mM24HrsDpDepColor = color;
                                int temp = Convert.ToInt32(o);
                                excelRowData.M24HrsDpDep = temp;
                            }
                        }
                    }

                    if (cCnt == 8)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mP24Color = color;
                                int temp = Convert.ToInt32(o);
                                excelRowData.P24 = temp;
                            }
                        }
                    }

                    if (cCnt == 9)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mCorrectedPressureColor = color;
                                int temp = Convert.ToInt32(o);
                                excelRowData.CorrectedPressure = temp;
                            }
                        }
                    }

                    if (cCnt == 10)
                    {
                        if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
                        {
                            object o = (range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            if (rCnt > 1)
                            {
                                int colorNumber = System.Convert.ToInt32(((Excel.Range)range.Cells[rCnt, cCnt]).Font.Color);
                                Color color = System.Drawing.ColorTranslator.FromOle(colorNumber);
                                excelRowData.mPressDepFromNormalColor = color;
                                int temp = Convert.ToInt32(o);
                                excelRowData.PressDepFromNormal = temp;
                            }
                        }
                    }
                }

                mExcelDataList.Add(excelRowData);
            }

            this.Text = "Loading complete!";
         
            xlWorkBook.Close(true, null, null);

            xlApp.Quit();

            releaseObject(xlWorkSheet);

            releaseObject(xlWorkBook);

            releaseObject(xlApp);
        }
        #endregion

        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Unable to release the Object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        } 

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar == 27)
                System.Windows.Forms.Application.Exit();
        }
      
        private void button3_Click(object sender, EventArgs e)
        {
            WriteToJPG();
            
            /*  //this is printing code.
            this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("A1", pictureBox1.Image.Width, pictureBox1.Image.Height);
            this.printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
            PageSettings ps = new PageSettings();
            ps.PaperSize = new PaperSize("A1", pictureBox1.Image.Width, pictureBox1.Image.Height);
            this.printDocument1.PrinterSettings.CreateMeasurementGraphics(ps);

            this.printDialog1.ShowDialog();
            this.printDialog1.PrintToFile = true;
            this.printDocument1.PrinterSettings = this.printDialog1.PrinterSettings;
            this.printDocument1.Print();
             * 
             * */
            
        }

        void WriteToJPG()
        {
            this.pictureBox1.Image.Save(Application.StartupPath + "\\map.jpeg", ImageFormat.Jpeg);
            this.Text = "Image file written";
        }

        void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.PageSettings.PaperSize = new PaperSize("A1", pictureBox1.Image.Width, pictureBox1.Image.Height);
            
            e.Graphics.DrawImageUnscaled(pictureBox1.Image, new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height));
            
        }

        bool mInEditMode = false;
        private void button4_Click(object sender, EventArgs e)
        {
            if (!mInEditMode)
            {
                mInEditMode = true;
                this.dataGridView1.Enabled = true;
                this.button4.Text = "End Edit Mode";
            }
            else
            {
                mInEditMode = false;
                this.dataGridView1.Enabled = false;
                this.button4.Text = "Start Edit Mode";
            }
        }

        void LoadXML()
        {
            XmlSerializer sr = new XmlSerializer(typeof(MapData));
            using (StreamReader sreader = new StreamReader(mDataFolder + CityLocationDetailsFileName))
            {
                try
                {
                    mMapData = sr.Deserialize(sreader) as MapData;
                }
                catch (Exception ex)
                {
                    this.Text = ex.Message;
                }
            }
        }

        //update the xml file with the new values.
        private void button5_Click(object sender, EventArgs e)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MapData));
            using (StreamWriter sw = System.IO.File.CreateText(Application.StartupPath + "\\" + CityLocationDetailsFileName))
            {
                try
                {
                    serializer.Serialize(sw, mMapData);
                }
                catch (Exception ex)
                {
                    this.statusStrip1.Text = ex.Message;
                }
                this.statusStrip1.Text = "Written";
            }
        }

       
        int xcoord = 0;
        int ycoord = 0;
        private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            xcoord = e.X;
            ycoord = e.Y;
            this.Text = e.X.ToString() + "   " + e.Y.ToString();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
            DataGridViewCell cell = row.Cells[e.ColumnIndex];
            int stationid =(int) cell.Value;
            foreach (CityLocationDetails cld in mMapData.mCityLocationDetails)
            {
                if (cld.StationID == stationid)
                {
                    cld.X = xcoord;
                    cld.Y = ycoord;
                }
                row.Cells[3].Value = xcoord;
                row.Cells[4].Value = ycoord;
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LoadAndProcessData();
        }

        //morning file
        private void button2_Click(object sender, EventArgs e)
        {
            mExcelFilename = mMapData.MorningFilename;
            LoadAndProcessData();
        }


        //evening file
        private void button6_Click(object sender, EventArgs e)
        {
            mExcelFilename = mMapData.EveningFilename;
            LoadAndProcessData();
        }

       
        
    }
}
